package cn.gan.loveofsoul.controller;

import cn.gan.loveofsoul.commons.result.ErrorMessage;
import cn.gan.loveofsoul.commons.result.Result;
import cn.gan.loveofsoul.commons.result.StatusCode;
import cn.gan.loveofsoul.entity.PhotoUploadRecord;
import cn.gan.loveofsoul.entity.vo.PhotoUploadRecordVO;
import cn.gan.loveofsoul.exception.BusinessException;
import cn.gan.loveofsoul.service.IPhotoUploadRecordService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ganwh
 * @since 2023-10-26
 */
@Controller
@RequestMapping("/photoUploadRecord")
public class PhotoUploadRecordController {
    @Autowired
    private IPhotoUploadRecordService photoUploadRecordService;

    /**
     * 功能描述: 新增上传记录
     *
     * @param photoUploadRecordVO
     * @return cn.gan.loveofsoul.commons.result.Result
     * @author ganwh 2023/11/8 14:45
     */
    @PostMapping("/")
    @ResponseBody
    public Result insert(@RequestBody @Valid PhotoUploadRecordVO photoUploadRecordVO) {
        return photoUploadRecordService.insertPhotoUploadRecord(photoUploadRecordVO);
    }

    /**
     * 功能描述: 分页查询相册上传记录
     *
     * @param pageIndex
     * @param pageSize
     * @param albumId
     * @return cn.gan.loveofsoul.commons.result.Result
     * @author ganwh 2023/11/8 18:06
     */
    @GetMapping("/queryList")
    @ResponseBody
    public Result queryList(@RequestParam(value = "pageIndex", defaultValue = "0") Integer pageIndex,
                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                            @RequestParam(value = "albumId") Integer albumId) {
        if (Objects.isNull(albumId)) {
            throw new BusinessException(StatusCode.BAD_REQUEST, ErrorMessage.MISSING_PARAMETER);
        }
        return photoUploadRecordService.pageQueryPhotoUploadRecord(pageIndex, pageSize, albumId);
    }

    @DeleteMapping("/")
    @ResponseBody
    public Result delete(@RequestBody Integer id) {
        if (Objects.isNull(id)) {
            throw new BusinessException(StatusCode.BAD_REQUEST, ErrorMessage.MISSING_PARAMETER);
        }
        return null;
    }
}
